require 'test/unit'
require 'semantictext/default_tag_factory' 
require 'rubygems'
require 'mocha'

class DefaultTagFactoryTest < Test::Unit::TestCase
  
  def setup
    @factory = SemanticText::DefaultTagFactory.new
  end
  
  def test_http
    tag = @factory.create_tag('http','//www.example.com')
    assert_equal(SemanticText::HTTPTag, tag.class)
    assert_equal("http://www.example.com",tag.link)
  end
  
  def test_mailto
    tag = @factory.create_tag('mailto','somebody@example.com')
    assert_equal(SemanticText::MailToTag, tag.class)
    assert_equal("somebody@example.com",tag.address)
  end
  
  def test_ftp
    tag = @factory.create_tag('ftp','//ftp.funet.fi/pub/standards/RFC/rfc959.txt')
    assert_equal(SemanticText::FTPTag, tag.class)
    assert_equal("ftp.funet.fi",tag.host)
    assert_equal("/pub/standards/RFC/rfc959.txt", tag.path)
  end
  
  def test_unregistered_tag
    assert_throws(:"c2:RecentChanges") {
      @factory.create_tag('c2','RecentChanges')
      }
  end

  def test_register_tag
    SemanticText::MailToTag.expects(:new).once().with('bigfoo','tag content text')
    @factory.register_tag('bigfoo',SemanticText::MailToTag)
    @factory.create_tag('bigfoo','tag content text')
  end
  
  def test_register_tag_with_nonstring_key
    assert_throws(:"must register a tag class with a String key, but was Array") { @factory.register_tag([],SemanticText::MailToTag) }
  end

end
